﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NorthWin_Test.Dao;
using System.Data;
using System.Collections;
using NorthWin_Test.Entity;

namespace NorthWin_Test.Biz
{
    public class CategoryBiz
    {
        public ArrayList GetAllCategory()
        {
            ArrayList arr = new ArrayList();
            CategoryDao dao = new CategoryDao();
            DataTable table = dao.GetAllCategory();
            arr = GetEntity(table);
            return arr;
        }

        public ArrayList GetEntity(DataTable table)
        {
            ArrayList arr = new ArrayList();
            foreach (DataRow row in table.Rows)
            {
                CategoryEntity en = new CategoryEntity();
                en.CategoryID = int.Parse(row["CategoryID"].ToString());
                en.CategoryName = row["CategoryName"].ToString();
                en.Description = row["Description"].ToString();
                arr.Add(en);
            }
            
            return arr;
        }

        public int AddCategory(CategoryEntity entity)
        {
            CategoryDao dao = new CategoryDao();
            int result = dao.AddCategory(
                    entity.CategoryID,
                    entity.CategoryName,
                    entity.Description
                );
            return result;
        }
    }
}
